﻿using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Daq
{
    public interface INavigationService
    {
        ObservableObject? CurrentViewModel { get; }
        void NavigateTo<T>() where T : ObservableObject;
        event Action? CurrentViewModelChanged;
    }
    public class NavigationService : INavigationService
    {
        private ObservableObject? currentViewModel;
        public ObservableObject? CurrentViewModel
        {
            get => currentViewModel;
            set
            {
                currentViewModel = value;
                CurrentViewModelChanged?.Invoke();
            }
        }

        public event Action? CurrentViewModelChanged;
        public void NavigateTo<T>() where T:ObservableObject => CurrentViewModel = App.Current.Services.GetService<T>();
    }
}
